home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / source / hotspot / viewer / sbcls.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-05  |  6.4 KB  |  195 lines

  1. /**************************************************************************
  2.  *
  3.  *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4.  *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5.  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6.  *  PURPOSE.
  7.  *
  8.  *  Copyright (c) 1993  Microsoft Corporation.  All Rights Reserved.
  9.  * 
  10.  **************************************************************************/
  11. /*
  12.     subcls.c:
  13.         Terminate -- stops playing the movie and closes it
  14.         OnButtonDown -- if clicked point on a hotspot,
  15.             a viewer command is executed
  16.         CleanupStuff -- removes properties from windows before they
  17.             are destroyed
  18.         SbClsProc -- subclasses the movie window
  19. */
  20. #include <windows.h>
  21. #include <mmsystem.h>
  22. #include <digitalv.h>
  23. #include <viewer.h>
  24. #include <string.h>
  25.  
  26. #include "hotspot.h"
  27.  
  28. extern char szMovieInfo[];
  29.  
  30. /*
  31.     Terminate -- pauses movie, then closes it with fileCloseMovie
  32. */ 
  33. void Terminate(PMOVIEINFO pMovieInfo)
  34. {
  35.     playMovie(pMovieInfo, 0);
  36.     fileCloseMovie(pMovieInfo, FALSE);
  37. }
  38.  
  39. /*
  40.     OnButtonDown -- walks through hotspot list.  For each hotspot,
  41.         uses PtInRect to see if its in the rect.  If it is, it uses
  42.         VwrCommand to transmit the hotspot's command to viewer.  Then
  43.         it looks at the Stop/Continue/Jump to setting and uses the return
  44.         value to handle Stop and Continue, or calls setMovie to do a
  45.         jump.
  46. */ 
  47. BOOL OnButtonDown(PMOVIEINFO pMovieInfo, USHORT msg, USHORT wp, LONG lp)
  48. {
  49.     PHOTSPOT pHotspot;
  50.     DWORD dwFrame;                      
  51.     POINT pt;
  52.     HWND hwnd;
  53.     
  54.     if (!pMovieInfo)
  55.         return FALSE;
  56.     
  57.     pHotspot = pMovieInfo->pHotspotList;
  58.     pt = MAKEPOINT(lp);
  59.     dwFrame = GetMovieFrame(pMovieInfo);
  60.     
  61.     while (pHotspot)
  62.         {        
  63.         if (dwFrame >= pHotspot->BeginFrame && dwFrame <= pHotspot->EndFrame)
  64.             {
  65.             if (PtInRect(&pHotspot->rc, pt) != 0)
  66.                 {                
  67.                 hwnd = GetParent(pMovieInfo->hwndParent);
  68.                 if (!hwnd)
  69.                     hwnd = pMovieInfo->hwndParent;
  70.                 VwrCommand(VwrFromHinst(GetWindowWord(hwnd, GWW_HINSTANCE)),
  71.                                 NULL, pHotspot->pszCommand, cmdoptNONE);
  72.                 switch (pHotspot->OnClick)
  73.                     {
  74.                     case ID_CONTINUE:
  75.                         return (TRUE);                        
  76.                     case ID_STOP:
  77.                         return (FALSE);
  78.                     case ID_JUMP:
  79.                         setMovie(pMovieInfo, pHotspot->ToFrame, NULL);
  80.                         pMovieInfo->dwCurrentFrame = pHotspot->ToFrame;
  81.                         pMovieInfo->fPlaying = FALSE;
  82.                         playMovie(pMovieInfo, 1);
  83.                         return (TRUE);                        
  84.                     default:
  85.                         return (TRUE);                                            
  86.                     }                                
  87.                 }
  88.             }
  89.         pHotspot = pHotspot->pNext;                        
  90.         }
  91.     return (TRUE);        
  92. }
  93.  
  94. /*
  95.     CleanupStuff -- Removes properties and hotspots from windows in
  96.         movieinfo structure.  Frees the handle to the movieinfo, too!
  97. */
  98. void CleanupStuff(HWND hwnd, PMOVIEINFO pMovieInfo, HANDLE hglb)
  99. {
  100.     RemoveProp(hwnd, (LPSTR)szMovieInfo);
  101.     if (pMovieInfo)
  102.     {
  103.         if (pMovieInfo->hwndParent)
  104.             RemoveProp(pMovieInfo->hwndParent, (LPSTR)szMovieInfo);
  105.         DeleteHotspotList(pMovieInfo);                
  106.     }
  107.     if (pMovieInfo)               
  108.         SetWindowLong (hwnd, GWL_WNDPROC,
  109.                 (LONG) pMovieInfo->lpfnOldProc);
  110.     GlobalUnlock(hglb);
  111.     GlobalFree(hglb);
  112. }
  113.  
  114. /*
  115.     SbClsProc -- catches WM_LBUTTONDOWN, MM_MCINOTIFY, and WM_DESTROY
  116.         messages.  See each message for more info.
  117.         Gets movieinfo ahead of time for all 3 message handlers.
  118. */ 
  119. LONG FAR PASCAL _export SbClsProc (HWND hwnd, USHORT msg,
  120.      USHORT wp, LONG lp)
  121. {
  122.     HANDLE hglb;
  123.     PMOVIEINFO pMovieInfo;
  124.     LRESULT lr;
  125.     
  126.     hglb = GetProp(hwnd, (LPSTR)szMovieInfo);
  127.     if (!hglb)
  128.         {
  129.         dbg("ERROR: Invalid global memory handle (no window property)");
  130.         pMovieInfo = NULL;
  131.         }
  132.     else pMovieInfo = (PMOVIEINFO)GlobalLock(hglb);
  133.  
  134.     switch (msg)
  135.     {
  136.         /*
  137.             WM_LBUTTONDOWN -- passes point to OnButtonDown and
  138.                 terminates movie if it returns FALSE.
  139.          */
  140.         case WM_LBUTTONDOWN:
  141.             if (0 == (OnButtonDown(pMovieInfo, msg, wp, lp)))                
  142.                 {
  143.                 Terminate(pMovieInfo);
  144.                 return 0L;
  145.                 }        
  146.             break;            
  147.     
  148.         case MM_MCINOTIFY:
  149.             /* This is where we check the status of an AVI  */
  150.             /* movie that might have been playing.  We do   */
  151.             /* the play with MCI_NOTIFY on so we should get */
  152.             /* a MCI_NOTIFY_SUCCESSFUL if the play      */
  153.             /* completes on it's own.           */
  154.             switch(wp){
  155.                 case MCI_NOTIFY_SUCCESSFUL:
  156.                     /* the play finished, let's rewind */
  157.                     /* and clear our flag.         */                
  158.                     dbg("subclass MCI_NOTIFY_SUCCESSFUL");
  159.                     pMovieInfo->fPlaying = FALSE;
  160.                     Terminate(pMovieInfo); /* this will call our WM_DESTROY */
  161.                     return 0L;
  162.                 }
  163.             break;            
  164.  
  165.         /*
  166.             WM_DESTROY -- calls the AVI's WM_DESTROY handler, so that
  167.                 AVI doesn't think this window exists when it acutally
  168.                 doesn't.  Then we Terminate() the movie and
  169.                 CleanupStuff() to free the movieinfo
  170.          */
  171.         case WM_DESTROY:
  172.             lr = CallWindowProc(pMovieInfo->lpfnOldProc, hwnd, msg, wp, lp);
  173.             Terminate(pMovieInfo);
  174.              CleanupStuff(hwnd,pMovieInfo,hglb);            
  175.             hglb = NULL;
  176.             pMovieInfo = NULL;
  177.         break;
  178.         default:
  179.             /* by default we want the AVI windowproc to do its normal thing */
  180.             lr = CallWindowProc(pMovieInfo->lpfnOldProc, hwnd, msg, wp, lp);
  181.     }
  182.  
  183.     /* at this point we may or may not have a movieinfo.  If we do,
  184.         we ought to unlock it.
  185.      */
  186.     if (pMovieInfo)
  187.         {
  188.         if (hglb)
  189.             GlobalUnlock(hglb);
  190.         return (lr);
  191.         }
  192.     else
  193.         return 0L;
  194. }
  195.